package model.admin;
import com.opensymphony.xwork2.ActionSupport;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;
import java.sql.*;
import vo.*;
import vo.mixed.*;
import model.admin.*;
import myutil.*;
public class CreateEventMo {
	SimpleDateFormat displayFormat = new SimpleDateFormat("HH:mm");
    SimpleDateFormat parseFormat = new SimpleDateFormat("hh:mm a");
    int event_id;
	public void createEvent(String creator_username, String event_name,
			String event_description, String event_date, String event_time,String event_location) throws Exception{
		// TODO Auto-generated method stub
		String[] date_formatted=event_date.split("/");
		String month=date_formatted[0];
		String day=date_formatted[1];
		String year=date_formatted[2];
		event_date=year+"-"+month+"-"+day;
		Date date = parseFormat.parse(event_time);
		System.out.println(event_time);
		
		event_time=displayFormat.format(date);
	
		try{
			Connect c=new Connect();
			c.dml("insert into event_details(event_name,event_description,event_date,event_time,event_creator_id,event_location) values('"+event_name+"','"+event_description+"','"+event_date+"','"+event_time+"','"+creator_username+"','"+event_location+"')");
			ResultSet rs=c.getResult("select max(event_id) as event_id from event_details");
			if(rs.next()){
				event_id=rs.getInt("event_id");
				
			}
			c.dml("insert into event_participation values('"+event_id+"','"+creator_username+"',0,0,0)");
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}

}
